/*
 * Generate Qingtian QTSM Attestation Doc
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#ifndef ENCLAVE_ATTESTATION_H
#define ENCLAVE_ATTESTATION_H

#include <sys/types.h>
#include "cms_comm.h"

enum rsa_key_size {
    RSA_2048 = 2048,
    RSA_3072 = 3072,
    RSA_4096 = 4096
};

struct rsa_keypair {
    void *keys;
};

/*
 * attestation_rsa_keypair_new() - Generate an RSA keypair used for attestation doc.
 * @key_size (input): The RSA keypair size.
 *
 * Context: Process context.
 *
 * Returns:
 * * The generated keypair on success.
 * * NULL on failure.
 */
struct rsa_keypair *attestation_rsa_keypair_new(enum rsa_key_size key_size);

/*
 * get_attestation_doc() - Generate attestation doc using Qingtian QTSM.
 * @keypair (input): The RSA keypair generated by @attestation_rsa_keypair_new.
 * @attestation_doc (output): The generated attestation doc.
 *
 * Context: Process context.
 *
 * Returns: The status of the operation.
 */
int get_attestation_doc(const struct rsa_keypair *keypair, struct stream_buf *attestation_doc);

/*
 * attestation_rsa_decrypt() - Decrypt the ciphertext data using the RSA private key.
 * @keypair (input): The RSA keypair generated by @attestation_rsa_keypair_new.
 * @cipher_symm_key (input): The encrypted symmetric key
 * @plain_symm_key (output): The plain text symmetric key (pass in an empty buffer,
 *                           enough space will be allocated for it with malloc)
 *
 * Context: Process context.
 *
 * Returns: The status of the operation.
 */
int attestation_rsa_decrypt(struct rsa_keypair *keypair,
    const struct stream_buf *cipher_symm_key,
    struct stream_buf *plain_symm_key);

/*
 * attestation_rsa_keypair_destroy() - Destroy the previously generated RSA keypair.
 * @keypair (input): The RSA keypair generated by @attestation_rsa_keypair_new.
 *
 * Context: Process context.
 *
 * Returns: void
 */
void attestation_rsa_keypair_destroy(struct rsa_keypair *keypair);

#endif
